
const app = getApp();
import Dialog from '../../../dist/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    enterprise_list:[],
    enterprise_current_page:1,
    enterprise_last_page:1,
    server_list:[],
    server_list_current_page:1,
    server_list_last_page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  edit(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageI/lawyerPlatform/enterprise/add/add?type=edit&id='+id,
    });
  },
  getData(){
    let urlStr = "";
    if(this.data.active == 0){
      urlStr = 'plugin.lawyer-platform.frontend.controllers.business.getBusiness'
    }else{
      urlStr = 'plugin.lawyer-platform.frontend.controllers.diy-form.getList'
    }
    app._postNetWork({
      url:app.getNetAddresss(urlStr),
      success:(res)=>{
        if(res.data.result == 1){
          if(this.data.active ==0){
            this.setData({
              enterprise_list:res.data.data.list.data,
              enterprise_last_page:res.data.data.list.last_page,
            })
          }else{
            this.setData({
              server_list:res.data.data.list.data,
              server_list_last_page:res.data.data.list.last_page,
            })
          }
        }else{
          app.tips(res.data.msg)
        }
      }
    })
  },
  to(e){
    let id = e.currentTarget.dataset.id,
    dataId = e.currentTarget.dataset.dataid;
    wx.navigateTo({
      url: '/packageI/enterprise/enterprise_form?id='+id+`&dataId=${dataId}`,
    });
  },
  onChange(event){
    this.setData({active:event.detail.index});
    if(this.data.active == 1){
      this.getData()
    }
  },
  handle() {
    wx.navigateTo({
      url: '/packageI/lawyerPlatform/enterprise/add/add?type=add',
    });
  },
  del_enterprise(e) {
    let id = e.currentTarget.dataset.id;
    Dialog.alert({
      title: "提示",
      message: "是否删除该企业"
    }).then(() => {
      app._postNetWork({
        url:app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.business.delete"),
        data:{id},
        success:(res)=>{
          if(res.data.result == 1){
            app.tips(res.data.msg);
            this.getData();
          }else{
            app.tios(res.data.msg)
          }
        }
      })
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMoreData()
  },
  getMoreData(){
    if(this.data.enterprise_current_page>=this.data.enterprise_last_page){
      return;
    }
    let page = this.data.enterprise_current_page+1;
    app._postNetWork({
      url:app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.business.getBusiness"),
      data:{page},
      success:(res)=>{
        if(res.data.result == 1){
          let list = this.data.enterprise_list.concat(res.data.data.list.data);
          console.log(list);
          this.setData({
            "enterprise_current_page":res.data.data.list.current_page,
            "enterprise_last_page":res.data.data.list.last_page,
            "enterprise_list":list
          })
        }else{
          app.tips(res.data.msg)
        }
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})